package com.nancy.ioc.BeanFactoryPostProcessor.importtest.entry;

import com.nancy.ioc.BeanFactoryPostProcessor.importtest.*;
import com.nancy.ioc.RegistryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource(value = "classpath:bean.properties")
@ImportResource(value = {"classpath:ioc-importresource.xml"})
@ComponentScan(basePackages = "com.nancy.ioc.BeanFactoryPostProcessor.importtest.componenttoscan")
@Import(value = {MyImportSelector.class, MyDeferredImportSelector.class, MyDeferredImportSelector2.class,
        MyImportBeanDefinitionRegistrar.class, MyImportConfiguration.class})
@ImportRegistrarFlag
public class CustomImport {

    @Autowired
    private Environment environment ;

    @Bean("registryBean")
    public RegistryBean registryBean(){
        String beanFieldName2 = environment.getProperty("bean.field.name2") ;
        System.out.println("获取@PropertySource 注入的properties ==》 bean.field.name2 = [" + beanFieldName2 + "] from environment");
        return new RegistryBean("CustomImport内@Bean加载的bean， beanFieldName2=" + beanFieldName2) ;
    }


}
